echo '########### begin create build directionry'

WRK_DIR=build
FMK_NAME=Component1
INSTALL_DIR=Products/${FMK_NAME}.framework
WORKSPACE_NAME=${FMK_NAME}
SCHEME_NAME=${FMK_NAME}
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

RELEASE_OS_DIR=${WRK_DIR}/iphoneos
RELEASE_SIMULATOR_DIR=${WRK_DIR}/iphonesimulator
DEVICE_DIR=${RELEASE_OS_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${RELEASE_SIMULATOR_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

if test -d $WRK_DIR; then
echo '########### directionry exist remove'
rm -f -r $WRK_DIR
fi

echo '########### begin pod install'

# 更新CocoaPods
pod install


# workspace方式
echo '########### begin build 真机'
xcodebuild -workspace ${WORKSPACE_NAME}".xcworkspace" -configuration "Release" -scheme ${SCHEME_NAME}  SYMROOT=$(PWD)/$RELEASE_OS_DIR -sdk iphoneos clean build

echo '########### begin build 模拟器'
xcodebuild -workspace ${WORKSPACE_NAME}".xcworkspace" -configuration "Release" -scheme ${SCHEME_NAME}  SYMROOT=$(PWD)/$RELEASE_SIMULATOR_DIR -sdk iphonesimulator clean build

echo '########### create product directionry'

if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"

cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"

echo '########### begin lipo framework'

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"

echo '########### mv build dir'

rm -r "${WRK_DIR}"

echo '########### build over success'
